<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2019/11/14 10:56
    // +----------------------------------------------------------------------
    // | Description:
    // +----------------------------------------------------------------------

namespace app\common\controller;

use app\admin\model\Logs;
use app\admin\model\Settings;
use think\Controller;
use think\Facade\Config;

class BaseController extends Controller{


    protected static $log;
    /**
     * 初始化操作
     * @return void
     */
    protected function initialize()
    {
        parent::initialize();

        // 初始化请求配置
        $this->initRequestConfig();

        // 初始化全局地址
        $this->initRequestUrl();


        // 系统应用参数

        // 上传配置
        $uploadConfig = Config::get('app.config.upload');

        // 图片配置
        $this->assign('uploadImgExt', $uploadConfig['image_config']['upload_image_ext']);
        $this->assign('uploadImgSize', $uploadConfig['image_config']['upload_image_size']);
        $this->assign('uploadImgMax', $uploadConfig['image_config']['upload_image_max']);

        // 视频配置
        $this->assign('uploadVideoExt', $uploadConfig['video_config']['upload_video_ext']);
        $this->assign('uploadVideoSize', $uploadConfig['video_config']['upload_video_size']);
        $this->assign('uploadVideoMax', $uploadConfig['video_config']['upload_video_max']);

        $GLOBALS['log']=0;
    }


    /**
     * BaseController constructor.
     * @param Logs $log
     */
    public function __construct(Logs $log){
            parent::__construct();
            self::$log=$log;
    }



    /**
     * 初始化请求配置
     * @return void
     */
    public function initRequestConfig()
    {
        // 定义是否GET请求
        defined('IS_GET') or define('IS_GET', $this->request->isGet());

        // 定义是否POST请求
        defined('IS_POST') or define('IS_POST', $this->request->isPost());

        // 定义是否AJAX请求
        defined('IS_AJAX') or define('IS_AJAX', $this->request->isAjax());

        // 定义是否PAJAX请求
        defined('IS_PJAX') or define('IS_PJAX', $this->request->isPjax());

        // 定义是否PUT请求
        defined('IS_PUT') or define('IS_PUT', $this->request->isPut());

        // 定义是否DELETE请求
        defined('IS_DELETE') or define('IS_DELETE', $this->request->isDelete());

        // 定义是否HEAD请求
        defined('IS_HEAD') or define('IS_HEAD', $this->request->isHead());

        // 定义是否PATCH请求
        defined('IS_PATCH') or define('IS_PATCH', $this->request->isPatch());

        // 定义是否为手机访问
        defined('IS_MOBILE') or define('IS_MOBILE', $this->request->isMobile());


        // 模块名称
        $module_name = $this->request->module();
        // 控制器名称
        $controller_name = $this->request->controller();
        // 操作方法名称
        $action_name = $this->request->action();

        // 定义模块名
        defined('MODULE_NAME') or define('MODULE_NAME', $module_name);
        // 定义控制器名
        defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $controller_name);
        // 定义操作方法名
        defined('ACTION_NAME') or define('ACTION_NAME', $action_name);

        // 自定义渲染
        $this->assign('module', strtolower($module_name));
        $this->assign('control', strtolower($controller_name));
        $this->assign('act', strtolower($action_name));

        //系统名称和版本号
        $this->assign('sys_version', VERSION);
        $this->assign('sys_name', SYSTEM_NAME);
    }

    /**
     * 初始化全局地址
     * @return void
     */
    public function initRequestUrl()
    {
        $this->assign('site_name', config('config')['site_name']);

        $this->meta();

    }

    /**
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2020/2/27
     * @name: meta
     * @describe:系统信息
     */
    public function meta(){
        $set=new Settings();
        $data=$set->getSetting();
        $this->assign('sys_info', $data);

    }

    /**
     * @return string
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2020/2/25
     * @name: session_ids
     * @describe:session
     */
    public function session_ids(){
        return session_id();
    }


    /**
     * @return string
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @name: makeToken
     * @describe:生成一个不会重复的字符串
     */
    public function makeToken()
    {
        $str = md5(uniqid(md5(microtime(true)), true)); //
        $str = sha1($str); //加密
        return $str;
    }


}
